package com.nullpointer.xchat.object;

import java.util.Collection;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class MessageContent {
	public enum MsgType {
		TEXT, IMAGE, UPDATE_INFO, SEND_TYPING, SEND_STOP_TYPING, 
		SEND_CHAT_VIDEO_REQUEST, SAY_HI_REQUEST, ONLINE, OFFLINE, 
		SAY_HI_REQUEST_LV2, SEND_VOICE_CHAT, SEND_VOICE_CALL_REQUEST, CHECK_FRIEND_ONLINE, 
		CHECK_USER_ONLINE, FRIEND_ONLINE, USER_ONLINE
	}

	private Integer fromUserID;
	private String name;
	private String content;
	private MsgType msgType;

	public Integer getFromUserID() {
		return fromUserID;
	}

	public void setFromUserID(Integer fromUserID) {
		this.fromUserID = fromUserID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public MsgType getMsgType() {
		return msgType;
	}

	public void setMsgType(MsgType msgType) {
		this.msgType = msgType;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static MessageContent fromJsonToMessageContent(String json) {
		try {
			MessageContent messageContent = new JSONDeserializer<MessageContent>()
					.use(null, MessageContent.class).deserialize(json);
			return messageContent;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String toJsonArray(Collection<MessageContent> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

//	public static Collection<MessageContent> fromJsonArrayToMessageContents(
//			String json) {
//		return new JSONDeserializer<List<MessageContent>>()
//				.use(null, ArrayList.class).use("values", MessageContent.class)
//				.deserialize(json);
//	}

}
